package org.example.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.mapper.SimStdPlanMapper;
import org.example.model.SimProject;
import org.example.model.SimStdPlan;
import org.example.model.common.Response;
import org.example.model.common.SimStdPlanQry;
import org.example.model.SimStrategyOption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author: Ran
 * @Date: 2021/9/22
 **/
@Service
public class StrategyService {

    @Autowired
    private SimStdPlanMapper simStdPlanMapper;

    /**
     * 获取策略
     *
     * @param simStdPlanQry
     * @return
     */
    public Response getStrategyOptions(SimStdPlanQry simStdPlanQry) {

        PageHelper.startPage(simStdPlanQry.getPageNum(), simStdPlanQry.getPageSize());
        PageInfo<SimStdPlan> simStdPlanPageInfo = new PageInfo<>(simStdPlanMapper.getPlanList(simStdPlanQry));

        List<Map<String, String>> strategyOptions = new ArrayList<>();

        simStdPlanPageInfo.getList().forEach(plan -> {
            Map<String, String> resultMap = SimStrategyOption.createOption(plan.getStrategyOptions());
            resultMap.put("taskName", plan.getTaskName());
            strategyOptions.add(resultMap);
        });
        PageInfo<Map<String, String>> mapPageInfo = new PageInfo<>(strategyOptions);
        mapPageInfo.setTotal(simStdPlanPageInfo.getTotal());
        return Response.buildSuccess(mapPageInfo);

    }
}
